package com.siyu.prewarn.mesuser.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.siyu.common.core.controller.BaseController;
import com.siyu.common.core.domain.AjaxResult;
import com.siyu.common.core.page.TableDataInfo;
import com.siyu.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.siyu.prewarn.mesuser.domain.Mesuser;
import com.siyu.prewarn.mesuser.service.IMesuserService;

/**
 * 预警对象Controller
 *
 * @author hrhy
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/prewarn/mesuser")
public class MesuserController extends BaseController {
    @Autowired
    private IMesuserService mesuserService;

    /**
     * 查询预警对象列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Mesuser mesuser) {
        startPage();
        List<Mesuser> list = mesuserService.selectMesuserList(mesuser);
        return getDataTable(list);
    }

    /**
     * 导出预警对象列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mesuser mesuser) {
        List<Mesuser> list = mesuserService.selectMesuserList(mesuser);
        ExcelUtil<Mesuser> util = new ExcelUtil<Mesuser>(Mesuser.class);
        util.exportExcel(response, list, "预警对象数据");
    }

    /**
     * 获取预警对象详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(mesuserService.selectMesuserById(id));
    }

    /**
     * 新增预警对象
     */
    @PostMapping
    public AjaxResult add(@RequestBody Mesuser mesuser) {
        return toAjax(mesuserService.insertMesuser(mesuser));
    }

    /**
     * 修改预警对象
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Mesuser mesuser) {
        return toAjax(mesuserService.updateMesuser(mesuser));
    }

    /**
     * 删除预警对象
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(mesuserService.deleteMesuserByIds(ids));
    }
}
